# -*- encoding: utf-8 -*-

"""
6.4.3 层次化索引
"""

import pandas as pd
import numpy as np

dt = ['2020-03-11', '2020-03-12','2020-03-13']
sc = ['000625.SZ','000762.SZ','600132.SH','600009.SH','600126.SH']
cn = ['成交额', '成交量']
idx = pd.MultiIndex.from_product([dt, sc], names=['日期', '代码'])
data = np.array([
	[422.08, 37091400],
	[73.65, 9315300],
	[207.04, 4127800],
	[510.59, 7233100],
	[63.28, 28911100],
	[471.78, 42471700],
	[59.2, 7724200],
	[156.82, 3143100],
	[853.83, 12350400],
	[52.84, 24828900],
	[789.1, 68771048],
	[57.01, 7741802],
	[223.06, 4496598],
	[1196.14, 17662768],
	[56.32, 27484360]
])

vom1 = pd.DataFrame(data, index=idx, columns=cn)
print(vom1)

dt = ['2020-03-11', '2020-03-12','2020-03-13']
sc = ['000625.SZ','000762.SZ','600132.SH','600009.SH','000882.SZ']
cn = ['成交额', '成交量']
cols = pd.MultiIndex.from_product([dt, cn], names=['日期', '数据'])
data = np.array([
	[422.08, 37091400, 471.78, 42471700, 789.1, 68771048],
	[73.65, 9315300, 59.2, 7724200, 57.01, 7741802],
	[207.04, 4127800, 156.82, 3143100, 223.06, 4496598],
	[510.59, 7233100, 853.83, 12350400, 1196.14, 17662768],
	[63.28, 28911100, 52.84, 24828900, 56.32, 27484360]
])

vom2 = pd.DataFrame(data, index=sc, columns=cols)
print(vom2)

print(vom1.loc['2020-03-11'])
print(vom1.loc['2020-03-11', '000625.SZ'])
print(vom1.loc['2020-03-11', '000625.SZ']['成交量'])

print(vom2['2020-03-11'])
print(vom2['2020-03-11', '成交额'])
print(vom2.loc['000625.SZ'])
print(vom2.loc['000625.SZ'][:,'成交额'])

